﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Data.OleDb;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Btn_Login_Click(object sender, EventArgs e)
    {
        //获取用户名和密码的长度，如果长度乘积为0则有一个为空
        if (0 == TBox_EmpID.Text.Length * TBox_Password.Text.Length)
        {
            Lb_Message.Text = "用户名或者密码不能为空。";
            return;
        }
        //下面判断用户输入密码与jwb_User表中密码是否一致
        string empID = TBox_EmpID.Text;
        string password = FormsAuthentication.HashPasswordForStoringInConfigFile(TBox_Password.Text,"MD5").ToLower();//将用户输入的密码转换为MD5
        DBOperate myDB = new DBOperate();
        myDB.SetCommandString(string.Format("Select * from jwb_Users Where EmpID = '{0}' and Password = '{1}'", empID, password));
        if (!myDB.ExecuteReader().HasRows)
        {
            Lb_Message.Text = "用户名或密码错误" + password;
            return;
        }
        myDB.CloseDB();
        //判断用户在党员系统中是否存在
        myDB = new DBOperate();
        myDB.SetCommandString(string.Format("Select * from party_PartyMember Where EmpID = '{0}'", empID));
        if (!myDB.ExecuteReader().HasRows)
        {
            Lb_Message.Text = "系统中无该用户，登陆失败";
            return;
        }
        Lb_Message.Text = "登陆成功！";
        myDB.CloseDB();
        if (Request.QueryString["ReturnUrl"] != null)
            Response.Redirect(Request.QueryString["ReturnUrl"].ToString());
        else
            Response.Redirect("default.aspx");
        


       
    }
}
